<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class RelationshipController extends BaseController
{
    public $validate = [
        "add" => ["rules" => [
            "follow_id" => "required|string|max:24",
        ]],
        "cancel" => ["rules" => [
            "follow_id" => "required|string|max:24",
        ]],
        "follower" => ["rules" => [
            "id" => "sometimes|required|string|max:24",
            "last_id" => "max:24",
        ]],
        "following" => ["rules" => [
            "id" => "sometimes|required|string|max:24",
            "last_id" => "max:24",
        ]],
    ];

    /**
     * @path /relationship/add
     * @category 关注关系
     * @title 关注
     * @method POST
     * @params [{"name":"follow_id","type":"text","required":1,"example":"","desc":"被关注的人的ID"}]
     * @resBody {"success":true,"statusCode":200,"result":{"attention_status":"关注关系，1没关注，2关注了，3自己，4互关"},"message":"OK"}
     */
    public function add(Request $request)
    {
        $params = $request->all();

        $data = service()->RelationshipService->onAdd($this->getBaseInfo($params));

        return $this->apiReturn($data);
    }

    /**
     * @path /relationship/cancel
     * @category 关注关系
     * @title 取消关注
     * @method POST
     * @params [{"name":"follow_id","type":"text","required":1,"example":"","desc":"被取消关注的人的ID"}]
     * @resBody {"success":true,"statusCode":200,"result":{"attention_status":"关注关系，1没关注，2关注了，3自己，4互关"},"message":"OK"}
     */
    public function cancel(Request $request)
    {
        $params = $request->all();

        $data = service()->RelationshipService->onCancel($this->getBaseInfo($params));

        return $this->apiReturn($data);
    }

    /**
     * @path /relationship/follower
     * @category 关注关系
     * @title 粉丝列表
     * @method POST
     * @params [{"name":"id","type":"text","required":0,"example":"","desc":"被查看用户ID，查看自己时可不传"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":true,"list":[{"id":"用户ID","attention_status":"关注关系，1没关系，2关注了，3自己，4互关","created_at":"创建时间戳","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}}]}}
     */
    public function follower(Request $request)
    {
        $params = $request->all();
        $data = service()->RelationshipService->onFollower($this->getBaseInfo($params), $params['user_id'] ?? 0);

        return $this->apiReturn($data);
    }

    /**
     * @path /relationship/following
     * @category 关注关系
     * @title 关注列表
     * @method POST
     * @params [{"name":"id","type":"text","required":0,"example":"","desc":"被查看用户ID，查看自己时可不传"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":true,"list":[{"id":"用户ID","attention_status":"关注关系，1没关系，2关注了，3自己，4互关","created_at":"创建时间戳","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}}]}}
     */
    public function following(Request $request)
    {
        $params = $request->all();

        $data = service()->RelationshipService->onFollowing($this->getBaseInfo($params), $params['user_id'] ?? 0);

        return $this->apiReturn($data);
    }
}
